package com.mvu.banana.common.widget;

/**
 * Created by IntelliJ IDEA.
 * User: gantz
 * Date: 5/29/11
 * Time: 7:37 PM
 * To change this template use File | Settings | File Templates.
 */

import java.util.ArrayList;

public class SimpleAutoCompletionItems implements CompletionItems {
  private String[] completions;

  public SimpleAutoCompletionItems(String[] items) {
    completions = items;
  }

  public String[] getCompletionItems(String match, int maxResults) {
    ArrayList<String> matches = new ArrayList<String>();
    int j = 0;
    for (int i = 0; i < completions.length && j < maxResults; i++) {
      if (completions[i].toLowerCase().startsWith(match.toLowerCase())) {
        matches.add(completions[i]);
        j++;
      }
    }
    return matches.toArray(new String[0]);
  }
}